FUNCTION YBC_SWS_CALLBACK_PR.
*"----------------------------------------------------------------------
*"*"本地接口：
*"  IMPORTING
*"     VALUE(IV_APPLEVEL) TYPE  YBC_SWS_APPROVER-APPLEVEL
*"     VALUE(IV_BUSINESSID) TYPE  YBC_SWS_REQUEST-BUSINESSID
*"     VALUE(IV_ACTION) TYPE  YBC_SWS_APPROVER-ACTION
*"     VALUE(IV_COMMENTS) TYPE  YBC_SWS_APPROVER-COMMENTS OPTIONAL
*"  EXPORTING
*"     VALUE(ES_MSG) TYPE  BAPIRET2
*"     VALUE(EV_FINISHED) TYPE  CHAR1
*"  TABLES
*"      ET_APPROVER_NEXT STRUCTURE  YBCS_SWS_APPROVER OPTIONAL
*"----------------------------------------------------------------------
**********************************************************************
* 若审批人由SwiftSAP配置实现，请勿修改ET_APPROVER_NEXT及EV_FINISHED 内容
* 若审批人由外部函数提供：若是最后一级审批，需设置EV_FINISHED = 'X'
*                        若不是最后一级审批，需提供ET_APPROVER_NEXT
**********************************************************************

  DATA:
    LV_BANFN    TYPE BAPI2009OB-PREQ_NO,
    LV_REL_CODE TYPE BAPIMMPARA-REL_CODE,
    LV_BNFPO    TYPE BAPI2009OB-PREQ_ITEM,
    LS_EBAN     TYPE EBAN,
    LS_XEBAN    TYPE UEBAN,
    LS_YEBAN    TYPE UEBAN,
    LT_XEBKN    TYPE STANDARD TABLE OF UEBKN,
    LT_YEBKN    TYPE STANDARD TABLE OF UEBKN,
    LT_XEBAN    TYPE STANDARD TABLE OF UEBAN,
    LT_YEBAN    TYPE STANDARD TABLE OF UEBAN,
    LS_RETURN   TYPE BAPIRETURN,
    LT_RETURN   TYPE STANDARD TABLE OF BAPIRETURN.

  CLEAR:
    ES_MSG.

  SPLIT IV_BUSINESSID AT '-' INTO LV_BANFN LV_BNFPO.
  CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
    EXPORTING
      INPUT  = LV_BANFN
    IMPORTING
      OUTPUT = LV_BANFN.

  CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
    EXPORTING
      INPUT  = LV_BNFPO
    IMPORTING
      OUTPUT = LV_BNFPO.

  SELECT SINGLE *
    FROM EBAN
    INTO LS_EBAN
   WHERE BANFN = LV_BANFN
     AND BNFPO = LV_BNFPO.
  IF SY-SUBRC <> 0.
    ES_MSG-TYPE = 'E'.
    ES_MSG-MESSAGE = TEXT-M03.
    RETURN.
  ENDIF.

  CASE IV_ACTION.
    WHEN 'REJECT'.
      MOVE-CORRESPONDING LS_EBAN TO LS_XEBAN.
      MOVE-CORRESPONDING LS_EBAN TO LS_YEBAN.

      LS_XEBAN-KZ = LS_YEBAN-KZ = 'U'.
      LS_XEBAN-BANPR = LS_YEBAN-BANPR = '08'. "拒绝发布

      APPEND LS_XEBAN TO LT_XEBAN.
      APPEND LS_YEBAN TO LT_YEBAN.

      CALL FUNCTION 'ME_UPDATE_REQUISITION'
        TABLES
          XEBAN = LT_XEBAN
          XEBKN = LT_YEBKN
          YEBAN = LT_YEBAN
          YEBKN = LT_YEBKN.
      IF SY-SUBRC <> 0.
        ES_MSG-TYPE = 'E'.
        ES_MSG-MESSAGE = TEXT-M04.
        RETURN.
      ENDIF.

    WHEN 'APPROVE'.
      CONDENSE IV_APPLEVEL.
      LV_REL_CODE = IV_APPLEVEL.
      CALL FUNCTION 'BAPI_REQUISITION_RELEASE'
        EXPORTING
          NUMBER                 = LV_BANFN
          REL_CODE               = LV_REL_CODE
          ITEM                   = LV_BNFPO
        TABLES
          RETURN                 = LT_RETURN
        EXCEPTIONS
          AUTHORITY_CHECK_FAIL   = 1
          REQUISITION_NOT_FOUND  = 2
          ENQUEUE_FAIL           = 3
          PREREQUISITE_FAIL      = 4
          RELEASE_ALREADY_POSTED = 5
          RESPONSIBILITY_FAIL    = 6
          OTHERS                 = 7.

      LOOP AT LT_RETURN INTO LS_RETURN WHERE TYPE = 'E' OR TYPE ='A'.
        ES_MSG-TYPE = 'E'.
        ES_MSG-MESSAGE = LS_RETURN-MESSAGE.
        EXIT.
      ENDLOOP.
    WHEN OTHERS.
  ENDCASE.
ENDFUNCTION.
